<template>
    <div class="white-box-form">
        <div>
            <span>状态：</span>
            <el-radio-group v-model="state.ruleForm.status">
                <el-radio
                    v-for="item in state.statusList"
                    :key="item.memberKey"
                    :value="item.memberKey"
                    >{{ item.memberName }}</el-radio
                >
            </el-radio-group>
        </div>
        <MyEditor class="mt-10" v-model:value="state.ruleForm.content" />

        <div class="foot-btn">
            <el-button
                type="primary"
                :loading="form_loading"
                @click="submitForm"
            >
                保存
            </el-button>
        </div>

        <go-back />
    </div>
</template>

<script setup>
import MyEditor from "@/components/MyEditor.vue";
import { reactive, inject, ref, onMounted } from "vue";
import { getForbiddenDetail, editForbidden } from "@/apis/system/forbidden";
import GoBack from "@components/GoBack.vue";
import { useDictStore } from "@stores/dict.js";

const dictStore = useDictStore();
dictStore.getDictMembers("data_status").then((res) => (state.statusList = res));

const $message = inject("$message");

const form_loading = ref(false);
const state = reactive({
    statusList: [],
    ruleForm: {
        content: "",
        status: 0,
        type: 0,
    },
});

onMounted(() => {
    getDetail();
});

const getDetail = async () => {
    const res = await getForbiddenDetail();
    if (res.data.code == 200) {
        state.ruleForm = res.data.data;
    } else {
        $message({ message: res.data.msg, type: "error" });
    }
};

// 提交表单
const submitForm = async () => {
    form_loading.value = true;
    const res = await editForbidden(state.ruleForm);

    form_loading.value = false;
    if (res.data.code == 200) {
        $message({
            message: "保存成功",
            type: "success",
        });
        getDetail();
    } else {
        $message({ message: res.data.msg, type: "error" });
    }
};
</script>
